import os.path
from pyurl.url import BaseURL, BaseRemoteURL, scheme_registry
from pyurl.connection import Connection

class LocalConnection(Connection):
    def open(self, url):
        pass
    
    def is_open(self):
        return True
    
    def close(self):
        pass
    
    def exists(self, path):
        return os.path.exists(path)

    def create_file(self, path):
        open(path, "w").close()
        
    def open_file(self, path, mode):
        return open(path, mode)

    def iter_folder(self, path):
        return os.listdir(path)


class PathURL(BaseURL):
    _scheme = "path"
    _connection_type = LocalConnection
    
    def __str__(self):
        return self._path

class FileURL(BaseRemoteURL):
    _scheme = "file"
    _connection_type = LocalConnection

scheme_registry.register(PathURL)
scheme_registry.register(FileURL)